<template>
  <div>
    <el-row>
      <el-button type="success" @click="toInfoPage" plain>录入</el-button>
      <el-button type="success" @click="open" plain>开立账户</el-button>
      <el-button type="success" @click="dialogFormVisible = true" plain>存取款</el-button>
      <el-button type="success" @click="findAndStatement" plain>查询与统计</el-button>
    </el-row>

    <el-dialog title="账号和类型" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="账号" :label-width="formLabelWidth">
          <el-input v-model="form.account" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="账号类型" :label-width="formLabelWidth">
          <el-radio v-model="form.accountType" label="1" border>活期</el-radio>
          <el-radio v-model="form.accountType" label="2" border>定期</el-radio>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="deposit">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default{
    name:"Index",
    data(){
      return{
        form:{
          account:'',
          accountType:''
        },
        dialogFormVisible: false,
        formLabelWidth: '120px'
      }
    },
    methods:{
      toInfoPage(){
        this.$router.push("/info")
      },
      open() {
        this.$prompt('请输入身份证号', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消'
        }).then(({ value }) => {
          this.$axios.post("/findInfo",{"idCard":value})
          .then(res=>{
            if(res.data.flag){
              this.$router.push("/startAccount")
            }else{
              this.$message({
                type: 'error',
                message: res.data.msg
              });
            }
          })
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消开户'
          });
        });
      },
      deposit(){
         this.$axios.post("/findAccount",this.form)
         .then(res=>{
            if(res.data.flag){
              this.$router.push(res.data.info)
            }else{
              this.$message({
                type: 'error',
                message: res.data.msg
              });
            }
         })
      },
      findAndStatement(){
          this.$router.push("/findAndStatement");
      }
    }
  }
</script>

<style>
</style>
